<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>       
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html style="overflow: hidden;">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>我的工作台</title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<style type="text/css">
        .fixed-table-body{height:auto;}
        .main_a{width:100%;height:100%}
</style>
</head>
<body>
<div class="main_a">
    <div  class="func_header">
        <span>当前位置 ：我的工作台 >待阅事项</span>
    </div>
    <div class="func_bar"><!--   功能内容-->
        <div class="search_container">
            <div class="advanced_search" style="width: 100%;margin: 3px 0 0;">
                <div class="advanced_search_div"></div>
                <input type="text" name="projectSource" id="projectSource" onkeypress="judge_enter()" placeholder="请输入项目名称" />
                <a class="magnifier" id="search" href="javascript:;"   onclick="refreshTable()"></a>
            </div>
        </div>
        <div class="btn_container">
            <a style="margin-top: 7px;" class="blue_btn" id="read" onclick="read()" href="javascript:;">标记为已阅</a>
        </div>
    </div>
    <div style="overflow: auto; width:98%;margin:0px auto 20px;">
		<table id="secretInvolvedLevelList" class="table table-bordered table_inline" ></table>
	</div>
</div>
</body>
<script type="text/javascript">
    var threeLevelList;
    var userId = "${userId}";
	var layerIndex;
    $(function(){
        loadTable();
    })
    function loadTable(){
    	if(userId == 'safesecret'){
    		getSafeReadList();    		
    	}else{
    		getReadList();
    	}
    }
    function judge_enter(){
        var theEvent = window.event || arguments.callee.caller.arguments[0];
        var code = theEvent.keyCode;
        if(code==13){
            refreshTable();
        }
    }
    function getSafeReadList(){
  	  threeLevelList = $("#secretInvolvedLevelList").bootstrapTable({
          url : '${_baseUrl}/myWorkbench/needReadEvent?rand='+Math.random(),
  		  pagination: true,
  		  pageList: [5, 10, 20, 50],
    	  singleSelect  : false,  
    	  queryParams: queryParams,
          columns : [{
              checkbox: true,
              cellStyle : function(value, row, index) {
                    if(row.messageStatus == '1'){
                      	return {css:{'color':'#AAAAAA'}};
         	         }else{
          	        	return {css:{'color':''}}; 
       	             }
               } , 
               formatter : function(value, row, index) {
            	   if(row.messageStatus == '1'){
                      	return {disabled: true};
         	         }else{
          	        	return; 
       	             }
            	   
               }
          },{
              field: 'messageId',
              title: 'ID',
              visible:false,
              width: 5
          },{
              field: 'messageContent',
              title: '待阅事项内容',
              width:200
          },{
              field: 'createTime',
              title: '发送时间',
              width: 100
          }],
        onLoadSuccess : function(data) {
        	var cellIndex=parseInt($(".table_inline th").length);
            $(".table_inline tr td").each(function(){
                if(this.cellIndex != cellIndex){
                    $(this).attr("title",$(this).text());
                }
            });
  		},
      })
    }
    
    
    function getReadList(){
    	  threeLevelList = $("#secretInvolvedLevelList").bootstrapTable({
              url : '${_baseUrl}/myWorkbench/needReadEvent?rand='+Math.random(),
    		  pagination: true,
    		  pageList: [5, 10, 20, 50],
      	  singleSelect  : false,  
      	  queryParams: queryParams,
            columns : [{
                checkbox: true,
                cellStyle : function(value, row, index) {
                      if(row.messageStatus == '1'){
                        	return {css:{'color':'#AAAAAA'}};
           	         }else{
            	        	return {css:{'color':''}}; 
         	             }
                 } , 
                 formatter : function(value, row, index) {
              	   if(row.messageStatus == '1'){
                        	return {disabled: true};
           	         }else{
            	        	return; 
         	             }
              	   
                 }
            },{
                field: 'messageId',
                title: 'ID',
                visible:false,
                width: 5
            },{
                field: 'messageContent',
                title: '待阅事项内容',
                width:200
            },{
                field: 'projectSource',
                title: '项目名称',
                width: 100
            },{
                field: 'createTime',
                title: '发送时间',
                width: 100
            }],
          onLoadSuccess : function(data) {
          	var cellIndex=parseInt($(".table_inline th").length);
              $(".table_inline tr td").each(function(){
                  if(this.cellIndex != cellIndex){
                      $(this).attr("title",$(this).text());
                  }
              });
    		},
        })
      }
    
    function queryParams(params){
		return {
		    pageSize: params.limit,
		    pageNo: params.pn,
		    sort : params.sort,
		    order : params.order,
            projectName : $("#projectSource").val() == "请输入" ? null : $("#projectSource").val(),
        }
	}
    function read(){
    	var selected = threeLevelList.bootstrapTable('getSelections');
    	if(selected.length < 1){
    		layer.msg("请选择需要标记的信息");
    		return false;
    	}
    	var ids = [];
    	for(var i=0;i<selected.length;i++){
    		ids.push(selected[i].messageId);
    	}
    	
		$.ajax({
			url : '${_baseUrl}/workbench/updateNeedHandleEvents?id='+ids,
			type : 'post', //数据发送方式 
			dataType : 'json', //接受数据格式 
			async : false,
			success : function(json) {
				if(json.code == '0'){
					layer.msg(json.message);
					refreshTable();
				}
			},
			error : function() {
				layer.msg("系统错误,请联系管理员");
			}
		});	
    }


    function refreshTable(){
    	threeLevelList.bootstrapTable('refresh');
    }

</script>
</html>